@scrider/formatter 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3226,7 +3226,14 @@ function htmlToDelta(html, options = {}) {
3226
3226
  }
3227
3227
  if (tagName === "br") {
3228
3228
  const hasMarker = node.hasAttribute("data-scrider-embed");
3229
- if (hasMarker || hasMeaningfulPrevSibling(node)) {
3229
+ if (hasMarker) {
3230
+ context.pushEmbed({ softBreak: true });
3231
+ return;
3232
+ }
3233
+ if (isBrowserEmptyLineFiller(node)) {
3234
+ return;
3235
+ }
3236
+ if (hasMeaningfulPrevSibling(node)) {
3230
3237
  context.pushEmbed({ softBreak: true });
3231
3238
  } else {
3232
3239
  context.pushNewline();
@@ -3681,6 +3688,39 @@ function hasMeaningfulPrevSibling(brNode) {
3681
3688
  }
3682
3689
  return false;
3683
3690
  }
3691
+ function isBrowserEmptyLineFiller(brNode) {
3692
+ const parent = brNode.parentNode;
3693
+ if (!parent) return false;
3694
+ const children = parent.childNodes;
3695
+ let prevElement = null;
3696
+ let foundCurrent = false;
3697
+ for (let i = 0; i < children.length; i++) {
3698
+ const child = children[i];
3699
+ if (!child) continue;
3700
+ if (child === brNode) {
3701
+ foundCurrent = true;
3702
+ continue;
3703
+ }
3704
+ if (!foundCurrent) {
3705
+ if (child.nodeType === NODE_TYPE.TEXT_NODE) {
3706
+ const text = (child.textContent ?? "").replace(/[\s\u200B]/g, "");
3707
+ if (text.length > 0) prevElement = null;
3708
+ } else if (isElement(child)) {
3709
+ prevElement = child;
3710
+ }
3711
+ } else {
3712
+ if (child.nodeType === NODE_TYPE.TEXT_NODE) {
3713
+ const text = (child.textContent ?? "").replace(/[\s\u200B]/g, "");
3714
+ if (text.length > 0) return false;
3715
+ } else if (isElement(child)) {
3716
+ const tag = child.tagName?.toLowerCase();
3717
+ if (tag !== "br") return false;
3718
+ }
3719
+ }
3720
+ }
3721
+ if (!prevElement) return false;
3722
+ return prevElement.tagName?.toLowerCase() === "br";
3723
+ }
3684
3724
  function findTagHandler(handlers, element, tagName) {
3685
3725
  const className = element.getAttribute("class");
3686
3726
  if (className) {